package com.example.cyh.bczapp.Code.BLL;

import android.widget.Toast;

import com.example.cyh.bczapp.Code.Helper.HttpHelper;
import com.example.cyh.bczapp.Code.Model.RemenberInfEntity;
import com.google.gson.Gson;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Dictionary;
import java.util.Hashtable;

/**
 * Created by cyh on 2017/5/23.
 */
public class RemenberBll {
    private final String BaseUrl="http://123.207.86.30/public/index.php/db/";
    public RemenberInfEntity GetTodayRemember(String planid,String u_id){
        String url=BaseUrl+"/Remenbercontrol/GetTodayinf";
        Dictionary<String, String> param = new Hashtable();
        param.put("p_id",planid);
        param.put("u_id",u_id);
        Date d = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String dateNowStr = sdf.format(d);
        param.put("time",dateNowStr);
        try {
            String  back= HttpHelper.POST(url,param);
            if(back.equals("start"))
                return new RemenberInfEntity();
            else if(back.equals("false"))
            {
                throw  new Exception("汇总更新昨天plan的数据失败");
            }
            Gson gson=new Gson();
            return gson.fromJson(back,RemenberInfEntity.class);
        }
        catch (Exception ex)
        {
            return null;
        }
    }
    public Boolean   Updatereminf(String  R_RWord,String R_EWord,String U_id,String P_id) {
        String url=BaseUrl+"Remenbercontrol/Updateinf";
        Dictionary<String, String> param = new Hashtable();
        param.put("p_id",P_id);
        param.put("u_id",U_id);
        if(R_RWord!="")
        param.put("RWord",R_RWord);
        if(R_EWord!="")
        param.put("EWord",R_EWord);
        try {
            String  back= HttpHelper.POST(url,param);
            return   back=="1";
        }
        catch (Exception ex)
        {
            return false;
        }
    }
}
